﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using KerriganMobile.Models;
using System.ComponentModel;
using System.Windows.Navigation;

namespace KerriganMobile
{
    public partial class MainPage : PhoneApplicationPage
    {
        private MainPageVo vo;
        public MainPage()
        {
            InitializeComponent();
            vo = new MainPageVo();
            DataContext = vo;
            vo.Login = "fdupond";
            vo.Password = "password";
            ApplicationManager.client.checkLoginCompleted += new EventHandler<MobileServiceWCF.checkLoginCompletedEventArgs>(client_checkLoginCompleted);
        }

        void client_checkLoginCompleted(object sender, MobileServiceWCF.checkLoginCompletedEventArgs e)
        {
            if (e.Result != null)
            {
                this.vo.Login = "";
                this.vo.Password = "";
                ApplicationManager.ID_CURRENT_INSTRUCTOR = e.Result.IdInstrutorDC;
                ApplicationManager.changeURI(this, "CustomerList");
            }
            else {
                MessageBox.Show("Connexion Error !");
            }
            
        }







        private void Button_Click(object sender, RoutedEventArgs e)
        {
            ApplicationManager.client.checkLoginAsync(vo.Login, vo.Password);
        }
    }

    public class MainPageVo : INotifyPropertyChanged
    { 
        private string _login;
        private string _password;

        public string Login { 
            get
            {
                return this._login;
            }
            set
            {
                this._login = value;
                OnPropertyChanged("Login");
            } 
        }

        public string Password
        {
            get
            {
                return this._password;
            }
            set
            {
                this._password = value;
                OnPropertyChanged("Password");
            }
        }


        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string property)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(property));
            }
        }

    }
}